<script>
import { getArticleList,deleteArticleList } from "@/api/eh-api";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 查询参数
      query: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
      },
      list:[]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      getArticleList(this.query)
        .then(({ rows, total }) => {
          this.list = rows;
          this.total = parseInt(total);
          this.loading = false;
          this.ids = [];
        })
        .catch(() => {
          this.loading = false;
        });
    },
    /**
     * 添加
     */
    creatItem:function(params) {
       this.$router.push({ path: 'article/creat' })
    },
    /**
     * 删除
     */
    deleteItem:function(rows) {
        console.log(rows)
        deleteArticleList({
          id:rows.id
        }).then( res => {
            if( res.code == 200 ){
              this.$message({
                message: '删除成功',
                type: 'success'
              });
              this.getList();
            }else{
              this.$message.error(res.msg);
            }
        })
    },
    /**
     * 统一路由
     */
    route(row) {
      console.log(row)
      this.$router.push({ path: 'article/creat', query: { id:row.id } })
    },
  },
};
</script>

<template>
  <div class="contain">
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="标题" prop="sender">
        <el-input v-model="query.title" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>

    <div class="mid-action">
      <div>
        <el-button type="primary" size="mini" @click="creatItem()">添加文章</el-button>
      </div>
    </div>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="缩略图" align="center" width="140">
        <template slot-scope="scope">
          <el-image class="thumbnail" fit="cover" :src="scope.row.logoImg"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="发布时间" align="center" prop="createTime" />
      <el-table-column label="来源" align="center" prop="sign">
        <template slot-scope="scope">
          <span>{{scope.row.sign == 0 ? '小程序' : '园区'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="route(scope.row, 'detail')">查看</el-button>
          <el-button size="mini" type="text" @click="route(scope.row, 'edit')">编辑</el-button>
          <el-button v-hasPermi="['enterpriseWechat:edit']" size="mini" type="text" @click="deleteItem(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
  </div>
</template>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 80px;
  height: 80px;
}
</style>
